package com.src.myapplication.ui.view.fragmentzhibo;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.Gson;
import com.src.myapplication.R;
import com.src.myapplication.base.BaseFragmentSwp;
import com.src.myapplication.bean.GuanZhuben;
import com.src.myapplication.config.UrlConfig;
import com.src.myapplication.utils.UIManager;
import com.src.myapplication.widget.CommonAdapter;
import com.src.myapplication.widget.PlayActivity;
import com.src.myapplication.widget.base.ViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2016/10/17.
 */
public class GuanZhu extends BaseFragmentSwp {
    private RecyclerView mRcv;
    @Override
    protected void initData(View view) {
        mRcv= (RecyclerView) view.findViewById(R.id.rcv);
    }


    @Override
    public int getLayoutId() {
        return R.layout.fragment_guanzhu;
    }

    @Override
    public int getid() {
        return R.id.sw;
    }

    @Override
    public String geturl() {
        return UrlConfig.ZhiBo.ZHIBO_GUANZHU;
    }


    @Override
    public Class<? extends Object> getben() {
        return GuanZhuben.class;
    }

    @Override
    public void addList(String string) {
    if(string!=null){
        Gson gson=new Gson();
        GuanZhuben guanZhuben = gson.fromJson(string, GuanZhuben.class);
        List<GuanZhuben.InfoBean.LivelistBean> livelist = guanZhuben.getInfo().getLivelist();

        CommonAdapter<GuanZhuben.InfoBean.LivelistBean> adapter=new CommonAdapter<GuanZhuben.InfoBean.LivelistBean>(getContext(),R.layout.fraagment_guanzhu_list,livelist) {
            @Override
            protected void convert(ViewHolder holder, GuanZhuben.InfoBean.LivelistBean guanzhu, int position) {
//                int users = guanzhu.getInfo().getLivelist().get(position).getUsers();//观看人数
//                String rtmp = guanzhu.getInfo().getLivelist().get(position).getRtmp();//播放地址
//                String nickname = guanzhu.getInfo().getLivelist().get(0).getUser().getNickname();//名称
//                String avatar = guanzhu.getInfo().getLivelist().get(0).getUser().getAvatar();//名称
//                String city = guanzhu.getInfo().getLivelist().get(position).getUser().getCity();//地址
//
                String avatar = guanzhu.getUser().getAvatar();
                String nickname = guanzhu.getUser().getNickname();
                SimpleDraweeView view = holder.getView(R.id.sdv);
                TextView view1 = holder.getView(R.id.tv);

                view.setImageURI(avatar);
                view1.setText(nickname);
                int uid = guanzhu.getUid();
                String rtmp = guanzhu.getRtmp();
                final String[] data=new String[]{String.valueOf(uid),nickname,avatar,rtmp};

                view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    UIManager.startActivity(getContext(), PlayActivity.class,data);
                }
            });
            }
        };
//        GridLayoutManager manager=new GridLayoutManager(getContext(),2);
//        manager.setOrientation(LinearLayoutManager.VERTICAL);
//        mRcv.setAdapter(adapter);
    }

    }
    @Override
    public void showLoadFailMsg() {

    }
}